import React, { Component } from 'react'
import { connect } from 'dva'
import { Form , Button ,Select, Table } from 'antd'
import SuperBtn from '../../components/SuperPut'
const { Option }=Select
@connect(state=>state.exam)
class ExamList extends Component {
  state={
    loading:false
  }
   componentDidMount(){
     this.listExam()
   }
   listExam=(payload={})=>{
    this.props.dispatch({
      type:"exam/listExam",
      payload
    })
  }
  get columns(){
    return [
      {
        title: '试卷信息',
        dataIndex: 'title',
        key: 'title',
        render: text => <span>{text}</span>,
      },
      {
        title: '创建人',
        dataIndex: 'user_name',
        key: 'user_name',
        render: text => <a>{text}</a>,
      },
      {
        title: '开始时间',
        dataIndex: 'start_time',
        key: 'start_time',
        render: text => <a>{text}</a>,
      },
      {
        title: '结束时间',
        dataIndex: 'end_time',
        key: 'end_time',
        render: text => <a>{text}</a>,
      },
      {
        title: '操作',
        key: '1',
        render:(text, record, index)=>{
          return <React.Fragment>
             <a onClick={()=>this.examDeail(record.exam_exam_id)} style={{ marginRight: 15 }} >详情</a>
          </React.Fragment>
        }
      },
    ]
  }
  examDeail(Id){
    this.props.history.push({pathname:'/exam/detail'})
    const { dispatch }=this.props
    dispatch({
      type:'exam/detailexam',
      payload:Id
    })
    console.log(Id)
  }
  render() {
    const { subject,examType,examList}=this.props;
    console.log(examList)
    return (
      <div>
        <div>
        <Form
        layout='inline'
        initialValues={{
          questions_type_id:"",
          subject_id:'',
          exam_id:''
        }
        }
        onFinish={this.examList}
      >
        <Form.Item label="题目类型" name="subject_id">
        <Select size="small"	 defaultValue="请选择" onChange={this.handleChange} style={{ width: 150 }}>
           <Option value='' key='1'>全部</Option>
           {
             (subject || []).map(item=>(
              <Option value={item.subject_id} key={item.subject_id}>{item.subject_text}</Option>
             ))
           }
        </Select>
        </Form.Item>
        <Form.Item label="考试类型" name="exam_id">
        <Select size="small"	 defaultValue="请选择" onChange={this.handleChange} style={{ width: 150 }}>
        <Option value='' key='1'>全部</Option>
           {
             (examType || []).map(item=>(
                <Option value={item.exam_id} key={item.exam_id}>{item.exam_name}</Option>
             ))
           }
        </Select>
        </Form.Item>
        <Form.Item>
          <Button type="primary" htmlType='submit'>查询</Button>
        </Form.Item>
      </Form>
       <Table loading={this.state.loading} columns={this.columns} dataSource={examList.exam} />
      </div>
      </div>
    )
  }
}
export default  ExamList